﻿@{
    ViewBag.Title = "短信任务执行周期";
    Layout = "~/Views/Shared/_layer.cshtml";
}


@model YouWei.Infrastructure.Entity.SmsTaskTime

@section style{
    <style>
        .form-horizontal .control-label {
            width: 20%;
            float: left;
            text-align: right;
        }

        .col-sm-3 {
            width: 80%;
            float: left;
        }
        .help-block{
            margin-bottom:0;
        }
    </style>
}
<form id="form1" class="form-horizontal">
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">周期类型：</label>
                        <div class="col-sm-3">
                            <select class="form-control" style="width:300px;" name="selType" id="selType">
                              @foreach (int v in Enum.GetValues(typeof(YouWei.Infrastructure.Enums.TimeTypeEnum)))
                              {
                                  if (v == Model.TimeType)
                                  {
                                    <option selected value="@v">@YouWei.Utility.EnumHelper.GetEnumDesc(typeof(YouWei.Infrastructure.Enums.TimeTypeEnum), v)</option>
                                  }
                                  else
                                  {
                                    <option value="@v">@YouWei.Utility.EnumHelper.GetEnumDesc(typeof(YouWei.Infrastructure.Enums.TimeTypeEnum), v)</option>
                                  }
                              }
                            </select>
                        </div>
                    </div>
                    @if (Model.ID > 0)
                    {
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="name">开始时间：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" value="@Model.StartTime" style="width:300px;" name="txtStartTime" maxlength="5" id="txtStartTime" />
                            </div>
                        </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">结束时间：</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" value="@Model.EndTime" style="width:300px;" name="txtEndTime" maxlength="5" id="txtEndTime" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">发送数量/次：</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" value="@Model.SendCount" style="width:300px;" name="txtSendCount" maxlength="50" id="txtSendCount" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">发送内容：</label>
                        <div class="col-sm-3">
                            <textarea cols="2" rows="6" class="form-control" name="txtSendContent" maxlength="65" id="txtSendContent" style="width:300px;" >@Model.SendContent</textarea>
                           
                        </div>
                    </div>
                    }
                    else
                    {
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="name">开始时间：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" value="" style="width:300px;" name="txtStartTime" maxlength="2" id="txtStartTime" placeholder="只能填写0-23的数值" />
                                <span style="color:red"></span>
                            </div>
                            
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="name">结束时间：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" value="" style="width:300px;" name="txtEndTime" maxlength="2" id="txtEndTime"  placeholder="只能填写0-23的数值"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="name">发送数量/次：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" value="" style="width:300px;" name="txtSendCount" maxlength="10" id="txtSendCount" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="name">发送内容：</label>
                            <div class="col-sm-3">
                                <textarea cols="2" rows="6" class="form-control" name="txtSendContent" maxlength="65" id="txtSendContent" style="width:300px;"></textarea>
                               
                            </div>
                        </div>
                    }
                </div>
                <div class="box-footer text-center">
                    <button class="btn btn-primary" type="button" id="btnSave">确 定 </button>
                    <button class="btn" type="button" id="cancel">取 消 </button>
                    <input type="hidden" id="timeId" name="timeId" value="@Model.ID" />
                    <input type="hidden" id="taskId" name="taskId" value="@ViewBag.TaskId" />
                </div>
            </div>

        </div>
        <!-- /.row -->
    </section>

</form>
@section scriptsBottom{
    <script type="text/javascript">
       $(document).ready(function () {
           initFormValidate();
       
           $("#btnSave").click(function(){
               save();
           });
           $("#cancel").click(function () {
               BMCW.closeAll();
           });
       });
       function initFormValidate() {
           $("#form1").bootstrapValidator({
               submitHandler: function (valiadtor, loginForm, submitButton) {
                   valiadtor.defaultSubmit();
               },
               fields: {
                   selType: {
                       validators: {
                           notEmpty: {
                               message: '请选择分类'
                           }
                       }
                   },
                   txtStartTime: {
                       validators: {
                           notEmpty: {
                               message: '开始时间不能为空'
                           },
                           regexp: {
                               regexp: /^[0-9]*$/,
                               message: '请输入数字'
                           },
                           callback: {
                               message: "请输入一个介于 0 和 23 之间的值",
                               callback: function (value, validator) {
                                   if (parseInt(value) >= 0 && parseInt(value) <= 23) {
                                       return true;
                                   }
                                   return false;
                               }
                           }
                       }
                   },
                   txtEndTime: {
                       validators: {
                           notEmpty: {
                               message: '结束时间不能为空'
                           },
                           regexp: {
                               regexp: /^[0-9]*$/,
                               message: '请输入数字'
                           },
                           callback: {
                               message: "请输入一个介于 0 和 23 之间的值",
                               callback: function (value, validator) {
                                   if (parseInt(value) >= 0 && parseInt(value) <= 23) {
                                       return true;
                                   }
                                   return false;
                               }
                           }
                       }
                   },
                   txtSendCount: {
                       validators: {
                           notEmpty: {
                               message: '发送数量不能为空'
                           },
                           regexp: {
                               regexp: /^[0-9]*$/,
                               message: '请输入数字'
                           }
                       }
                   },
                   txtSendContent: {
                       validators: {
                           notEmpty: {
                               message: '发送内容不能为空'
                           },
                           stringLength: {
                               max: 65,
                               message: '不超过65个字符'
                           }
                       }
                   }
               }
           });
       }

       function save()
       {
           var bootstrapValidator = $("#form1").data('bootstrapValidator');
           bootstrapValidator.validate();

           if (bootstrapValidator.isValid()) {
               var url = '@Url.Action("SaveTaskTime", "Sms")'
               BMCW.ajax({
                   url: url,
                   type: "POST",
                   data: {
                       TaskID: $("#taskId").val(),
                       ID: $("#timeId").val(),
                       StartTime: $("#txtStartTime").val(),
                       EndTime: $("#txtEndTime").val(),
                       SendCount: $("#txtSendCount").val(),
                       TimeType: $("#selType").val(),
                       SendContent: $("#txtSendContent").val()
                   },
                   success: function (o) {
                       if (o.status == 0) {
                           BMCW.msg("保存成功",function(){
                               BMCW.closeAll();
                               parent.search();
                           });
                       } else {
                           BMCW.alert("保存失败");
                       }
                   }
               });
           }
       }

    </script>
}
